﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using UnityEngine.EventSystems;
using ET;
using Demo;

namespace Marx
{
    public class UILogin
    {
        public const string kName = "Login";
        public const string kPath = "ui/login.prefab";
    }

    [UIRegister(UILogin.kName, UILogin.kPath, UIType.Panel)]
    public class UILoginController : UILoginControllerBasic
    {
        private bool logining_ = false;
        protected override void OnClickLogin()
        {
            if(logining_)
            {
                return;
            }
            Log.Info("Click Login");
            SendMessage().Coroutine();
        }

        private async ETTask SendMessage()
        {
            logining_ = true;
            var result = await Player.Login("123", "123");
            logining_ = false;
            if(result == ResultCode.OK)
            {
                Close();
                //UIManager.Instance.Show(UILobby.kName);
            }
            else if(result < ET.ErrorCore.ERR_Exception)
            {
                UIManager.Instance.ShowErrorTipsContent("链接服务器失败");
            }
            else
            {
                UIManager.Instance.ShowErrorTipsContent("登录失败");
            }
            //var session = ZoneManager.Instance.GetMainSession();
            //if (session == null || session.IsDisposed)
            //{
            //    session = ZoneManager.Instance.Connect("127.0.0.1", 20001, ZoneManager.Instance.Main);
            //}
            //var resp = await session.Call(new C2GTestReqeust() { Content = "Hellow world" }) as C2GTestResponse;
            //UnityEngine.Debug.Log("消息返回：" + resp.Content);
        }

        protected override void OnDrag(PointerEventData eventData)
        {
            Log.Info("Begin Drag", LogColor.Yellow);
        }

        protected override void OnEndDrag(PointerEventData eventData)
        {
            Log.Info("End Drag", LogColor.Yellow);
        }
    }
}
